<?php
require_once './libraries/function.php';
$path = "data/films.txt";
$full_path = realpath($path);
$films = mreadFile($path);
$rating = NULL;
?>
<form method="POST">
    <input type="text" name="rating">
    <input type="submit" name="submit" value="Search">
</form>

<?php if (isset($_POST['submit'])):?>
    <?php $rating = (int)$_POST['rating'];?>
<?php endif;?>
<?php foreach ($films as $item):?>
    <?php   $film = explode(";", $item);
            $img = trim($film[0]); 
    ?>
    <?php   if (empty($rating)):?>
                <img src = 'public/films/<?php echo $film[1] ?>'> 
                <?php echo $film[2]?>
                <?php echo $film[3] ?>
                <br>
    <?php else:?>
            <?php   if ($rating < (int)$film[2]):?>
                <img src = 'public/films/<?php echo $img ?>'> 
                <?php echo $film[1]?>
                <?php if (!empty($film[2])) echo $film[2] ?>
                <br>
           <?php endif;?>
    <?php endif;?>
                
<?php endforeach;?>   